package com.lw.spring.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/7 21:45
 */
@Aspect//声明增强类
@Component//让spring来创建
public class LogAdvice {

    @Pointcut("execution(* com.lw..*.*(..))")
    public void pointcut(){

    }

////    @Before("execution(* com.lw..*impl.*(..))")//这是一个前置注解
//    @Before("pointcut()")
//    public void kaishi(JoinPoint joinPoint){
//        System.err.println(joinPoint.toString());
//        System.out.println("开始执行方法了");
//    }
//
////    @AfterReturning("execution(* com.lw..*impl.*(..))")
//    @AfterReturning("pointcut()")
//    public void jieshu(){
//        System.out.println("写入日志完成");
//    }
//


    @Around("pointcut()")
    public Object huanrao(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕之前");
        System.out.println("环绕之前");
        Object proceed = joinPoint.proceed();
        System.out.println("返回的结果是："+proceed);
        System.out.println("环绕之后");
        System.out.println("环绕之后");
        return proceed;

    }
}
